﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import Classes.*;
    import flash.filters.*;
    import flash.text.*;

    public class SpriteButton extends GameSprite {

        protected const NORMAL:int = 0;
        protected const HOVER:int = 1;
        protected const DOWN:int = 2;
        protected const MAX_STATES:int = 3;

        protected var m_selected:Boolean = false;
        protected var m_down:Boolean = false;
        protected var m_over:Boolean = false;
        protected var m_enabled:Boolean = true;
        protected var m_clickCallback:Function;
        protected var m_imageInst:Array;

        public function SpriteButton(_arg1:Class, _arg2:Class, _arg3:Class, _arg4:Function=null, _arg5:String=""){
            this.m_imageInst = [null, null, null];
            super();
            addEventListener(MouseEvent.MOUSE_DOWN, this.onMouseDown);
            addEventListener(MouseEvent.MOUSE_UP, this.onMouseUp);
            addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            this.m_clickCallback = _arg4;
            addEventListener(MouseEvent.CLICK, this.onMouseClick);
            this.buttonMode = true;
            this.useHandCursor = true;
            this.m_imageInst[this.NORMAL] = new (_arg1)();
            this.m_imageInst[this.DOWN] = new (_arg3)();
            this.m_imageInst[this.HOVER] = new (_arg2)();
            var _local6:int;
            while (_local6 < this.MAX_STATES) {
                addChild(this.m_imageInst[_local6]);
                _local6++;
            };
            if (_arg5 != ""){
                this.makeText(_arg5);
            };
            this.updateImageState();
        }
        public function setEnabled(_arg1:Boolean):void{
            this.m_enabled = _arg1;
        }
        protected function makeText(_arg1:String):void{
            m_textField = new TextField();
            m_textField.multiline = false;
            m_textField.wordWrap = false;
            m_textField.text = _arg1;
            m_textField.width = this.m_imageInst[this.NORMAL].width;
            m_textField.height = 0;
            m_textField.selectable = false;
            m_textField.embedFonts = true;
            m_textField.antiAliasType = AntiAliasType.ADVANCED;
            m_textField.gridFitType = GridFitType.PIXEL;
            m_textField.autoSize = TextFieldAutoSize.CENTER;
            var _local2:TextFormat = new TextFormat();
            var _local3:Number = TextFieldUtil.getLocaleFontSize(24, 13, [{
                locale:"de",
                size:24
            }, {
                locale:"fr",
                size:24
            }, {
                locale:"es",
                size:14
            }]);
            _local2.font = EmbeddedArt.DEFAULT_FONT_NAME_BOLD;
            _local2.color = 16579429;
            _local2.align = TextFormatAlign.CENTER;
            _local2.size = _local3;
            var _local4:Array = [new GlowFilter(0, 1, 3, 3, 10), new GlowFilter(0xFFFFFF, 1, 2, 2, 10), new DropShadowFilter(2, 90, 0, 0.5)];
            m_textField.setTextFormat(_local2);
            m_textField.filters = _local4;
            addChild(m_textField);
            m_textField.y = 15;
            m_textField.height = 24;
            m_textField.mouseEnabled = false;
        }
        public function getTextField():TextField{
            return (m_textField);
        }
        protected function updateImageState():void{
            var _local1:int;
            if (this.m_down){
                _local1 = this.DOWN;
            } else {
                if (this.m_over){
                    _local1 = this.HOVER;
                } else {
                    _local1 = this.NORMAL;
                };
            };
            var _local2:int;
            while (_local2 < this.MAX_STATES) {
                this.m_imageInst[_local2].visible = (_local1 == _local2);
                _local2++;
            };
        }
        protected function onMouseOver(_arg1:MouseEvent):void{
            if (this.m_enabled){
                this.m_over = true;
                this.updateImageState();
            };
        }
        protected function onMouseOut(_arg1:MouseEvent):void{
            if (this.m_enabled){
                this.m_over = false;
                this.updateImageState();
            };
        }
        protected function onMouseDown(_arg1:MouseEvent):void{
            if (this.m_enabled){
                this.m_down = true;
                this.updateImageState();
                Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.onMouseUp);
                _arg1.stopPropagation();
                _arg1.stopImmediatePropagation();
            };
        }
        protected function onMouseUp(_arg1:MouseEvent):void{
            if (this.m_enabled){
                this.m_down = false;
                this.updateImageState();
                Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.onMouseUp);
                _arg1.stopPropagation();
                _arg1.stopImmediatePropagation();
            };
        }
        protected function onMouseClick(_arg1:MouseEvent):void{
            if (((this.m_enabled) && (!((this.m_clickCallback == null))))){
                this.m_clickCallback(_arg1);
            };
            _arg1.stopPropagation();
            _arg1.stopImmediatePropagation();
        }

    }
}//package Display 
